package cn.dzz.importor;

import cn.dzz.annotation.MyEnableAutoConfiguration;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.io.support.SpringFactoriesLoader;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author DaiZhiZhou
 * @file Autowired
 * @create 2020-08-18 16:32
 */

public class MyImportSelector implements ImportSelector {

    private Class<?> getMyFactoryLoaderClass(){
        return MyEnableAutoConfiguration.class;
    }

    private List<String> getConfiguration(){
        return SpringFactoriesLoader.loadFactoryNames(
            getMyFactoryLoaderClass(),MyImportSelector.class.getClassLoader()
        );
    }

    public String[] selectImports(AnnotationMetadata annotationMetadata) {
        return StringUtils.toStringArray(getConfiguration());
    }
}
